/**
 * 合作伙伴
 * @author Qasim <15750783791@163.com>
 * @version 2016/9/5
 */
var self = phone = id = uid = tid =  '';

document.addEventListener('plusready' , ready ,  false);

function ready(){
	
	self = plus.webview.currentWebview();
	
	var memberInfo = plus.storage.getItem('memberInfo');
	
	memberInfo = $.parseJSON(memberInfo);
	
	uid = memberInfo.aid;
	
 	//我的收藏
 	plus.nativeUI.showWaiting('加载中');
 	
 	$.ajax({  
 			type:"post", 
 			url:apiRoot + '/Home/Article/myCollection/',
 			data:{
 				uid : uid   
 			},
 			dataType : 'json', 
 			success : function(data){ 
 				
 				plus.nativeUI.closeWaiting();  
 				 
 				if(data){ 
 					$.each(data, function(k  , v) {
 						if(v.tid == 25 || v.tid == 28 || v.tid == 29){
							var html = '<div data-phone="'+v.phone+'" data-contacts="'+v.contacts+'" data-id="'+v.id+'" data-tid="'+v.tid+'" data-company="'+v.company_name+'" class="margin-top-5 table-view-cell background-w overflow-h home-list home-list-2 info collection'+v.id+'">';
								html += '<div class="mui-pull-right"><div><span class="mui-ellipsis-2 font-15 line-h-23 title">'+v.title+'</span><div class="content" style="display:none">'+v.body+'</div>';
								html += '<span class="font-14 color-c addtime">'+v.addtime+'</span></div></div><div class="mui-pull-left"><img src="'+getImgUrl(v.litpic)+'"/></div></div>';
							v.tid == 28 ?  $('#item1mobile .mui-scroll').append(html) : (v.tid == 29 ?  $('#item2mobile .mui-scroll').append(html) : $('#item5mobile .mui-scroll').append(html));
 						}else if(v.tid == 4){
 							var html = '<div  data-id="'+v.id+'" data-tid="'+v.tid+'" data-phone="'+v.phone+'" class="position-re margin-top-5 info collection'+v.id+'""><img src="'+getImgUrl(v.litpic)+'"/>';
								html += '<div class="span-bar color-white font-14"><div class="content" style="display:none">'+v.body+'</div>';
								html += '<span class="mui-pull-left mui-col-xs-9 title">'+v.title+'</span>';
								html += '<span class="mui-pull-left mui-col-xs-3 mui-text-right addtime">'+v.addtime+'</span></div></div>';
 							$('#item4mobile .mui-scroll').append(html); 
 						}else if(v.tid == 27){
 							var html = '<div data-phone="'+v.phone+'" data-addr="'+v.address+'" data-contacts="'+v.contacts+'" data-id="'+v.id+'" data-tid="'+v.tid+'" data-company="'+v.company_name+'" data-xueli="'+v.education+'" data-number="'+v.number+'" data-exp ="'+v.experience+'" class="background-w info table-view table-view-cell collection'+v.id+'"">';
								html += '<li class="font-17"><span class="title">'+v.title+'</span></li><div class="content" style="display:none">'+v.body+'</div>';
								html += '<li class=" line-h-23"><span  class="color-zx-2 font-16  salary">'+v.salary+'</span></li>';
								html += '<li><span class="color-c font-12 addtime">'+v.addtime+'</span></li></div>';
 							$('#item6mobile .mui-scroll').append(html); 
 						}else if(v.tid == 30){
 							var html = '<div  data-id="'+v.id+'" data-tid="'+v.tid+'" class="table-view-cell info table-view background-w overflow-h bbs-list-1 margin-top-5 collection'+v.id+'"">';
								html += '<i class="mui-pull-left "><img src="'+getImgUrl(v.avatar)+'"/></i><div class="mui-pull-left margin-bottom-10">';
								html += '<li class="overflow-h"><span class="mui-pull-left nickname">'+v.nickname+'</span><span class="mui-pull-right"><span class="iconfont color-c font-14">&#xe622;</span><span>'+v.number+'</span></span>';
								html += '</li><li class="font-12 color-c addtime">'+v.addtime+'</li></div>';
								html += '<div class="clear-both"><span class="ellipsis-1 title">'+v.title+'</span><div class="content" style="display:none">'+v.body+'</div></div></div>';
 							$('#item7mobile .mui-scroll').append(html);
 						}
 					});
 					
 					
 					$('.info').unbind();
					$('.info').on('click' , function(){
						var tid = $(this).attr('data-tid'); 
						if(tid == 28){
							plus.nativeUI.showWaiting('跳转中...');
							var yqhc_inf = plus.webview.create('yqhc-inf.html' , 'yqhc-inf' , {} , { 
								page : self.id,
								aid : $(this).attr('data-id') , 
								tid : tid ,
								pic : $(this).find('img').attr('src'),
								title : $(this).find('.title').text(),
								addtime : $(this).find('.addtime').text(),
								company : $(this).attr('data-company'),
								contacts : $(this).attr('data-contacts'),
								phone : $(this).attr('data-phone'),
								body : $(this).find('.content').html()
		
							});
							yqhc_inf.addEventListener('loaded', function (){
								yqhc_inf.show('pop-in');
								plus.nativeUI.closeWaiting();
							})
						}else if(tid == 29){
							plus.nativeUI.showWaiting('跳转中...');
							var jsfw_inf = plus.webview.create('jsfw-inf-1.html' , 'jsfw-inf-1' , {} , {
								page : self.id,
								aid : $(this).attr('data-id') , 
								tid : tid,
								pic : $(this).find('img').attr('src'),
								title : $(this).find('.title').text(),
								addtime : $(this).find('.addtime').text(),
								company : $(this).attr('data-company'),
								contacts : $(this).attr('data-contacts'),
								phone : $(this).attr('data-phone'),
								body : $(this).find('.content').html()
		
							});
							jsfw_inf.addEventListener('loaded', function (){
								jsfw_inf.show('pop-in');
								plus.nativeUI.closeWaiting();
							})
						}else if(tid == 26){
							plus.nativeUI.showWaiting('跳转中...');
							var hy_inf = plus.webview.create('hy-inf.html' , 'hy-inf' , {} , {
								page : self.id,
								aid : $(this).attr('data-id') , 
								tid : tid, 
								title : $(this).find('.title').text(),
								body : $(this).find('.content').html(),
							});
							hy_inf.addEventListener('loaded', function (){
								hy_inf.show('pop-in');
								plus.nativeUI.closeWaiting();
							})
						}else if(tid == 4){ 
							plus.nativeUI.showWaiting('跳转中...');
							var hd_inf = plus.webview.create('hd-inf.html' , 'hd-inf' , {} , {
								page : self.id,
								tid : tid ,
								phone : $(this).attr('data-phone'), 
								title : $(this).find('.title').text(),
								body : $(this).find('.content').html() ,
								aid : $(this).attr('data-id')
							});
							hd_inf.addEventListener('loaded', function (){
								hd_inf.show('pop-in');
								plus.nativeUI.closeWaiting();
							})	
						}else if(tid == 27){
							plus.nativeUI.showWaiting('跳转中...');
							var qzzp_inf = plus.webview.create('qzzp-inf.html' , 'qzzp-inf' , {} , { 
								page : self.id,
								aid : $(this).attr('data-id') , 
								tid : tid,
								title : $(this).find('.title').text(),
								addtime : $(this).find('.addtime').text(),
								salary : $(this).find('.salary').text(),
								company : $(this).attr('data-company'),
								education : $(this).attr('data-xueli'),
								number :  $(this).attr('data-number'),
								experience : $(this).attr('data-exp'),
								contacts : $(this).attr('data-contacts'),
								phone : $(this).attr('data-phone'),
								address : $(this).attr('data-addr'),
								body : $(this).find('.content').html()
							});
							
							qzzp_inf.addEventListener('loaded', function (){
								qzzp_inf.show('pop-in');
								plus.nativeUI.closeWaiting();
							})	
						}else if(tid == 30){
							plus.nativeUI.showWaiting('跳转中...');
							var bbs_inf = plus.webview.create('bbs-inf.html', 'bbs-inf', {}, {
								page : self.id,
								avatar : $(this).find('img').attr('src'),
								nickname : $(this).find('.nickname').text(),
								title : $(this).find('.title').text(),
								addtime : $(this).find('.addtime').text(),
								aid : $(this).attr('data-id'),
								tid : tid,
								body : $(this).find('.content').html()
							}); 
							bbs_inf.addEventListener('loaded', function (){
								bbs_inf.show('pop-in');
								plus.nativeUI.closeWaiting();
							})	
						}
						
					})
 				}
 			},
 			error : function(e){
 				console.log(JSON.stringify(e))
 				toast('连接超时,请检查网络');
 				plus.nativeUI.closeWaiting();
 			}
 			
 		});
 		 
}


window.addEventListener('cancel',function(event){
	
    var id = event.detail.id;
    
    var type = event.detail.type;
    
    if(type == '取消收藏'){
    	
    	console.log(type + ','+id)
    	$('.collection' + id).hide();
    	
    } else{
    	
    	$('.collection' + id).show();
    	
    }
});
